<?php
class Users extends CI_Model {

	var $id_user = '';
	var $cd_user_type = '';
	var $nm_user = '';
	var $nm_lastname = '';
	var $nm_company = '';
	var $nm_email = '';
	var $nm_phone = '';
	var $nm_country = '';
	var $nm_city = '';
	var $nm_pass = '';
	var $nm_paypalcode = '';
	
	
	function __construct()
	{
		parent::__construct();
	}
	
	function save($entry)
	{
		$this->nm_user  	= $entry['name'];
		$this->cd_user_type	= $entry['type'];
		$this->nm_lastname 	= $entry['lastname'];
		$this->nm_company 	= $entry['company'];
		$this->nm_email 	= $entry['email'];
		$this->nm_phone 	= $entry['phone1'][0].$entry['phone1'][1];
		$this->nm_country 	= $entry['country'];
		$this->nm_city 		= $entry['city'];
		$this->nm_pass 		= md5($entry['pass']);
		
		$this->db->insert('users', $this);
	}
	
	function delete($email)
	{
		
		$this->db->delete('users', array('nm_email' => $email));
	}
	
	function get_all($limit=10000)
	{
		$query = $this->db->get('users', $limit);
		return $query->result();
	}
	
	function login($email, $password)
	{
		$this->db->select('id_user, nm_email, nm_pass, nm_user, nm_country');
		$this->db->from('users');
		$this->db->where('nm_email', $email);
		$this->db->where('nm_pass', md5($password));
		$this->db->limit(1);

		$query = $this->db->get();
		
		if($query->num_rows() == 1){
			return $query->result();
		} else {
			return false;
		}
	}

}